#pragma once

#ifndef _OSMUTEX_H_
#define _OSMUTEX_H_

#include <stdlib.h>
//#include <afxwin.h>



class OSMutex
{
    public:

        OSMutex();
        ~OSMutex();

        void Lock();
        void Unlock();
        
        // Returns true on successful grab of the lock, false on failure
        BOOL TryLock();

    private:

	CRITICAL_SECTION fMutex;

};

class   OSMutexLocker
{
    public:

        OSMutexLocker(OSMutex *inMutexP) : fMutex(inMutexP) { if (fMutex != NULL) fMutex->Lock(); }
        ~OSMutexLocker() {  if (fMutex != NULL) fMutex->Unlock(); }
        
        void Lock()         { if (fMutex != NULL) fMutex->Lock(); }
        void Unlock()       { if (fMutex != NULL) fMutex->Unlock(); }
        
    private:

        OSMutex*    fMutex;
};

#endif //_OSMUTEX_H_



